import essayCard from "@/components/essayCard/essayCard.vue";
import * as allUrls from '../../utils/allUrls.js'
import { VideoList } from "../../api/videoList.js";


export default {
    name: "essayList",
    components: {essayCard},
    inject: ['reloadView', 'reload'],
    data() {
        return {
            loadingEssay: true,
            essayName: '',
            listsNum: 10,
            test: 0,
            showMoreTitle: '点击加载更多',
            recEssayInfo: '',
            essayInfo: [
				{id:123,
				url:123,
				title:123,
				oTitle:123,
				username:123}
			],
			pageNum:1,
			pageSize:10,
			videoType:null,
        }
    },
    methods: {
        //点击文章
        toEssay(val) {
            this.$router.push({path: '/essayInfo', query: {id: val}})
        },
        //新建文章
        /* toAddEssay() {
            this.$router.push('/addEssay')
        }, */
        // 加载更多
        loadMore() {
            this.pageSize += this.listsNum;
			this.getEssay();
            if (this.pageSize >= this.test) {
                this.showMoreTitle = '已经没有更多了哦！'
            }
        },
		// 切换视频类别
		chouseType(type) {
		    this.pageSize += this.listsNum;
			this.videoType = type;
		    this.getEssay();
		    if (this.pageSize >= this.test) {
		        this.showMoreTitle = '已经没有更多了哦！'
		    }
		},
        //随机文章推荐
        /* randomEssay(a, b) {
            return Math.random() > .5 ? -1 : 1;
        }, */
        //获取文章信息
        getEssay() {
            /* allUrls.getEssay({
                title: val,
            }, 'post').then(res => {
                return res.json();
            }).then(data => {
                if (+data.status === 200) {
                    //往期文章
                    this.essayInfo = data.data;
                    this.test = +data.data.length;
                    if (this.listsNum >= this.test) {
                        this.showMoreTitle = '已经没有更多了哦！';
                    }
                    this.loadingEssay = false;
                } else {
                    this.$message.error("获取文章信息错误！");
                    return false;
                }
            }).catch(err => {
                console.log(err);
                this.$message.error("获取文章信息错误！");
                return false;
            }); */
			VideoList({
				pageNum:this.pageNum,
				pageSize:this.pageSize,
				videoType:this.videoType,
			}).then(response => {
				console.log(response.rows)
				// this.essayInfo.put(response.rows)
				this.essayInfo = response.rows;
				this.test = response.total;
				console.log(this.essayInfo)
			});
        },
    },
    mounted() {
        //this.reload();
        /* this.essayName = this.$route.query.essayName;
        if (this.essayName) {
            this.getEssay(this.essayName);
        } else {
            this.getEssay();
        } */
		this.getEssay();
    },
    watch: {
        /* $route() {
            this.reloadView();
        } */
    }
}
